package com.example.service;

import com.example.consts.RbmConst;
import com.example.dao.EnrollDao;
import com.example.model.pojo.Enroll;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


import java.util.Date;
import java.util.Map;
import java.util.UUID;

/**
 * @Description //TODO
 * @Date 2022/9/21 10:48
 * @Author cxy
 **/
@Component
public class RbmSaveService {
    @Autowired
    private EnrollDao enrollDao;

    @RabbitHandler
    @RabbitListener(queues = RbmConst.SIMPLE_SEC_QUEUE)
    public void testSave(Map<String,Object> maps){
        System.out.println(">>>报名信息生成中<<<");
        Integer cId = (Integer) maps.get("cId");
        String username = (String) maps.get("username");

        Enroll o = new Enroll();
        o.setEnrollNo(UUID.randomUUID().toString());
        //核心数据的设置
        o.setSId(cId);
        o.setUsername(username);

        o.setCreateDate(new Date());
        o.setStatus(0);
        enrollDao.save(o);
    }
}
